package com.site.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by shengquan.wu on 2018/6/6.
 */
public class TimeHandler implements InvocationHandler {

    private Object target;

    public TimeHandler(Object target) {
        this.target = target;
    }

    /**
     *
     * @param proxy 被代理的对象
     * @param method 被代理对象的方法
     * @param args 方法的参数
     * @return Object 方法的返回值
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        long start = System.currentTimeMillis();
        System.out.println("汽车开始行驶...");

        method.invoke(target);

        System.out.println("汽车结束行驶...");
        long end = System.currentTimeMillis();
        System.out.println("汽车耗时"+(end-start)+"毫秒");
        return null;
    }
}
